package com.zara.store.common;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileHelper {

	private File file;

	public FileHelper(String filename) {
		file = new File(filename);
	}

	public void addLine(String line) {
		System.out.println(line);
		try {
			if (!file.exists()) {
				file.createNewFile();
			}
			if (file.canWrite()) {
				FileWriter fw = null;
				BufferedWriter bw = null;
				try {
					fw = new FileWriter(file, true);
					bw = new BufferedWriter(fw);
					bw.append(line);
					bw.newLine();
				} finally {
					try {
						if (bw != null)
							bw.close();
					} finally {
						if (fw != null)
							fw.close();
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
